const VuetifyLoaderPlugin = require('vuetify-loader/lib/plugin');
const LodashModuleReplacementPlugin = require('lodash-webpack-plugin');
import webpack from 'webpack';

export default {
  srcDir: 'src/',
  
  server: {
    port: 3000,
    host: '0.0.0.0',
  },

  router: {
    extendRoutes(routes, resolve) {
      routes.push({
        name: 'custom',
        path: '*',
        component: resolve(__dirname, 'src/pages/error/404.vue'),
      });
    },
  },

  render: {
    resourceHints: false,
  },

  // Global page headers (https://go.nuxtjs.dev/config-head)
  head: {
    title: '英伦留声机',
    meta: [
      { charset: 'utf-8' },
      { name: 'viewport', content: 'width=device-width, initial-scale=1' },
      //{ hid: 'description', name: 'description', content: '' }
    ],
    link: [{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }],
  },

  // Global CSS (https://go.nuxtjs.dev/config-css)
  css: ['~assets/css/layout.css', '~assets/css/global.css', '~assets/css/font.css', '~assets/css/link.css', '~assets/css/dropdown.css'],

  // Plugins to run before rendering page (https://go.nuxtjs.dev/config-plugins)
  plugins: [
    '~plugins/vue-wechat-title',
    '~plugins/vue-paginate',
    '~plugins/axios',
    '~plugins/vue-loading-template',
    //{src: '~plugins/vue-loading-template', ssr: false}
  ],

  // Auto import components (https://go.nuxtjs.dev/config-components)
  components: true,

  // Modules for dev and build (recommended) (https://go.nuxtjs.dev/config-modules)
  buildModules: [],

  // Modules (https://go.nuxtjs.dev/config-modules)
  modules: [
    // https://go.nuxtjs.dev/bootstrap
    ['bootstrap-vue/nuxt', { icons: false }],
    // https://go.nuxtjs.dev/axios
    '@nuxtjs/axios',
    '@nuxtjs/robots',
  ],

  robots: {
    UserAgent: '*',
    Disallow: ['/phpmyadmin', '/media', '/search'],
  },

  // Axios module configuration (https://go.nuxtjs.dev/config-axios)
  axios: {
    proxy: true,
    prefix: '/',
    credentials: true,
	retry: { retries: 3 }
  },

  proxy: {
    '/api/': {
	  target: 'http://api.britmusic.cn',
      //target: 'https://www.britmusic.cn',
      //pathRewrite: {
      //  '^/api': '/api', 
      //},
    },
  },

  // Build Configuration (https://go.nuxtjs.dev/config-build)
  build: {
    //analyze: true,
    //assetFilter: function(assetFilename) {
    //    return assetFilename.endsWith('.js');
    //},
	//publicPath: 'https://www.britmusic.cn/_nuxt/',
    optimization: {
      splitChunks: {
        chunks: 'async',
        minSize: 30000,
        maxSize: 0,
        minChunks: 1,
        maxAsyncRequests: 7,
        maxInitialRequests: 3,
        cacheGroups: {
          common: {
            name: 'common',
            chunks: 'initial',
            priority: 2,
            minChunks: 2,
          },
        },
      },
    },
    extend(config, ctx) {
      config.plugins.unshift(new LodashModuleReplacementPlugin());
      config.module.rules[2].use[0].options.plugins = ['lodash'];
    },
    //extractCSS: { allChunks: true },
    //plugins: [
    //	new webpack.IgnorePlugin({
    //	  resourceRegExp: /\.\/icons/,
    //	  contextRegExp: /_bootstrap-vue@2.17.3@bootstrap-vue/,
    //	})
    //]
  },

  transpile: [/^vuetify/],
  extend(config, ctx) {
    config.plugins.push(new VuetifyLoaderPlugin());
  },
};
